﻿using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Configuration;
namespace DotNetNuke.Modules.ActiveSocialMigrator.Data
{
    public class Connection
    {
        #region "Private Members"
        private DotNetNuke.Framework.Providers.ProviderConfiguration _providerConfiguration = DotNetNuke.Framework.Providers.ProviderConfiguration.GetProviderConfiguration("data");
        internal string connectionString;
        internal string objectQualifier;
        internal string databaseOwner;
        internal string databaseObjectPrefix = "activesocial_";

        internal string dbPrefix;
        #endregion
        #region "Constructors"
        public Connection()
        {
            connectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;
            DotNetNuke.Framework.Providers.Provider objProvider = (DotNetNuke.Framework.Providers.Provider)_providerConfiguration.Providers[_providerConfiguration.DefaultProvider];

            objectQualifier = objProvider.Attributes["objectQualifier"];
            if (!string.IsNullOrEmpty(objectQualifier) & objectQualifier.EndsWith("_") == false)
            {
                objectQualifier += "_";
            }

            databaseOwner = objProvider.Attributes["databaseOwner"];
            if (!string.IsNullOrEmpty(databaseOwner) & databaseOwner.EndsWith(".") == false)
            {
                databaseOwner += ".";
            }
            dbPrefix = databaseOwner + objectQualifier + databaseObjectPrefix;
        }
        #endregion
    }
}
